//
//  BaseTabBarVC.swift
//  FastDevelop
//
//  Created by IOS1 on 2025/6/26.
//

import UIKit


enum TabbarType: CaseIterable {
    case home
    case note
    case mine
    
    var imageName: String {
        switch self {
        case .home:
            return "tab_home"
        case .note:
            return "tab_note"
        case .mine:
            return "tab_mine"
        }
    }
    
    var selImageName: String {
        return "\(imageName)_sel"
    }

    var controller: UIViewController {
        switch self {
        case .home:
            return HomeViewController()
        case .note:
            return NoteViewController()
        case .mine:
            return MyselfViewController()
        }
    }
}

class BaseTabBarVC: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        setupUI()
        navigationController?.navigationBar.isTranslucent = true
    }
    
    private func setupUI() {
        viewControllers = TabbarType.allCases.map({ type in
            let vc = BaseNavVC(rootViewController: type.controller)
            vc.tabBarItem = UITabBarItem(title: nil,
                                         image: UIImage(named: type.imageName),
                                         selectedImage: UIImage(named: type.selImageName))
            vc.tabBarItem.imageInsets =  UIEdgeInsets(top: 6, left: 0, bottom: -6, right: 0)
            vc.tabBarItem.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: 2)
            return vc
        })
        
//        delegate = self
        
        /// style
        let appearance = UITabBarAppearance()
        appearance.configureWithOpaqueBackground()
        appearance.backgroundColor = .white
        tabBar.standardAppearance = appearance
        tabBar.scrollEdgeAppearance = tabBar.standardAppearance
    }

}
